#!/bin/bash
# Script which obtains xensource base path.
# Citrix Systems Inc, 2011
#
# Notes:
# - The configuration file "xapi.conf" is first looked for in "/etc",
#   and, if not found there, in the same directory as the script itself.
# - If the configuration file doesn't contain the "base_path" property,
#   the value returned defaults to "/opt/xensource".

DEFAULT_CONF="/etc/xapi.conf"

if [ -e "${DEFAULT_CONF}" ]; then
  CONF=${DEFAULT_CONF}
else
  SCRIPTS_DIR=`dirname ${0}`
  CONF="${SCRIPTS_DIR}/xapi.conf"
fi

if [ -e "${CONF}" ]; then
  BASE_PATH=`grep "^[^#]" "${CONF}" | grep "base_path" | awk -F '=' '{print $2}'`
fi

if [ -z "${BASE_PATH}" ]; then
  BASE_PATH="/opt/xensource"
fi

echo -n ${BASE_PATH}
